package api.transform;

import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 合流
 * Union
 * 可以合并多条流，但数据类型需一致
 */
public class TransformTest6 {

    public static void main(String[] args) throws Exception {
        /**运行环境*/
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        /**输入数据源source1*/
        DataStreamSource<Tuple3<String, String, String>> source1 = env.fromElements(new Tuple3<>("aaa", "张三", "gg"));

        /**输入数据源source2*/
        DataStreamSource<Tuple3<String, String, String>> source2 = env.fromElements(
                new Tuple3<>("bbb", "李四", "gg"),
                new Tuple3<>("ccc", "李思", "mm")
        );

        /**输入数据源source3*/
        DataStreamSource<Tuple3<String, String, String>> source3 = env.fromElements(
                new Tuple3<>("ddd", "王五", "gg"),
                new Tuple3<>("eee", "赵二", "gg"),
                new Tuple3<>("fff", "王舞", "mm")
        );
        /**1、合并流*/
        source1.union(source2,source3).print();
        env.execute();
    }
}
